<?php
class raovat_model extends CI_Model
{
	function __construct()
	{
		parent::__construct();
		$this->load->helper('img_helper');  
	}
	
	function get_all_list($limit, $start)
	{
		$this->db->where('bl_active',1);
		$this->db->order_by('dt_modify', 'DESC') ;
		return $this->db->get('raovat', $limit, $start)->result();
	}
	
	// Tong so san pham
	function get_total_raovat()
	{
		$this->db->where('bl_active',1);
		return $this->db->get('raovat')->num_rows();
	}
	
	function get_raovat_by_id($id)
	{
		$this->db->where('raovat_id', $id);
		return $this->db->get('raovat')->row();
	}
	
	function save($data, $id=0)
	{
		if(!empty($id))
		{
			$this->db->where('raovat_id', $id);
			if($this->db->update('raovat', $data))
			{
				return true ;
			}else{
				return false ;
			}
		}else{
			if($this->db->insert('raovat', $data))
			{
				return true ;
			}else{
				return false ;
			}
		}
	}
	
	function del($id)
	{
		$this->db->where('raovat_id', $id);
		if($this->db->delete('raovat', $data))
		{
			return true ;
		}else{
			return false ;
		}
	}
	
	// table relate
	function get_all_class($limit=40, $start=0)
	{
		$this->db->where('bl_active',1);
		$this->db->order_by('sort_no', 'ASC') ;
		return $this->db->get('class', $limit, $start)->result();
	}
	
	function get_all_town($limit=70, $start=0)
	{
		$this->db->where('bl_active',1);
		$this->db->order_by('sort_no', 'ASC') ;
		return $this->db->get('town', $limit, $start)->result();
	}
}
?>
